#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <stdio.h>

void signal_handler(int signal);
void safe_exit(int r);

/*****************************************************************************/
int  main(int argc, char *argv[])
/*****************************************************************************/
{
		signal(SIGINT,signal_handler);

		printf("vme_test by alex.kaplan@web.de built: %s %s\n\n",
					 __DATE__, __TIME__);

		safe_exit(0);
}
/*****************************************************************************/

/*---------------------------------------------------------------------------*/
void signal_handler(int signal)
/*---------------------------------------------------------------------------*/
{
		if(signal == SIGINT) {
				printf("\n\nCTRL-C pressed\n");
				safe_exit(2);
		} else
				psignal(signal, "signal_handler(): unknown signal!");
}
/*---------------------------------------------------------------------------*/


/*---------------------------------------------------------------------------*/
void safe_exit(int r)
/*---------------------------------------------------------------------------*/
{
		printf("\nsafe_exit()\n");

		printf("vmesysreset..."); fflush(stdout);
		if(int r=vmesysreset(crate)) {
				printf("error: vmesysreset() returned %d\n\n",r)
		}
		sleep(1);	printf("ok\n");

    if(crate > -1 ) {
				printf("closing crate\n\n"); close(crate);
		}

		exit(r);
}
/*---------------------------------------------------------------------------*/
